<?php

//演示php基础运算符
$a = 10;
$b = 5;
echo "a = " . $a . " b = " . $b . "<br>";

//算术运算符
echo "a + b = " . ($a + $b) . "<br>";
echo "a - b = " . ($a - $b) . "<br>";
echo "a * b = " . ($a * $b) . "<br>";
echo "a / b = " . ($a / $b) . "<br>";
echo "a % b = " . ($a % $b) . "<br>";

//赋值运算符
$c = $a;
echo "c = a, c = " . $c . "<br>";
$c += $b;
echo "c += b, c = " . $c . "<br>";
$c -= $b;
echo "c -= b, c = " . $c . "<br>";
$c *= $b;
echo "c *= b, c = " . $c . "<br>";
$c /= $b;
echo "c /= b, c = " . $c . "<br>";
$c %= $b;
echo "c %= b, c = " . $c . "<br>";

//比较运算符
if ($a == $b) {
    echo "a 等于 b" . "<br>";
} else {
    echo "a 不等于 b" . "<br>";
}

if ($a != $b) {
    echo "a 不等于 b" . "<br>";
} else {
    echo "a 等于 b" . "<br>";
}

if ($a > $b) {
    echo "a 大于 b" . "<br>";
} else {
    echo "a 不大于 b" . "<br>";
}

if ($a < $b) {
    echo "a 小于 b" . "<br>";
} else {
    echo "a 不小于 b" . "<br>";
}

if ($a >= $b) {
    echo "a 大于等于 b" . "<br>";
} else {
    echo "a 小于 b" . "<br>";
}

if ($a <= $b) {
    echo "a 小于等于 b" . "<br>";
} else {
    echo "a 大于 b" . "<br>";
}

//逻辑运算符
if ($a > 0 && $b > 0) {
    echo "a 和 b 都大于 0" . "<br>";
} else {
    echo "a 和 b 至少有一个不大于 0" . "<br>";
}

if ($a > 0 || $b > 0) {
    echo "a 和 b 至少有一个大于 0" . "<br>";
} else {
    echo "a 和 b 都不大于 0" . "<br>";
}

if (!($a > 0)) {
    echo "a 不大于 0" . "<br>";
} else {
    echo "a 大于 0" . "<br>";
}

//字符串运算符
$str1 = "Hello";
$str2 = "World";
echo $str1 . " " . $str2 . "<br>";
echo $str1 . $str2 . "<br>";
echo $str1 .= $str2 . "<br>";

//数组运算符
$arr1 = array("a" => "apple", "b" => "banana");
$arr2 = array("c" => "cat", "d" => "dog");
print_r($arr1 + $arr2);
echo "<br>";
var_dump($arr1 == $arr2);
echo "<br>";
var_dump($arr1 === $arr2);
echo "<br>";
var_dump($arr1 != $arr2);
echo "<br>";
var_dump($arr1 <> $arr2);
echo "<br>";
var_dump($arr1 !== $arr2);
echo "<br>";

//三元运算符
echo ($a > $b) ? "a 大于 b" : "a 不大于 b";
